package com.ls.demo.http.service.impl;

import com.google.gson.Gson;
import com.ls.demo.bean.Command;
import com.ls.demo.bean.InfraRedCommand;
import com.ls.demo.bean.RoomBoxInfo;
import com.ls.demo.enums.MessageAttrEnum;
import com.ls.demo.http.service.DownloadService;
import lombok.extern.java.Log;
import org.springframework.stereotype.Service;

import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author liShan
 * @date 2019/9/4 22:52
 * @see MessageAttrEnum
 */
@Service("downloadEquServiceImpl_22")
@Log
public class DownloadEquServiceImpl implements DownloadService {

    @Override
    public String execute(String str, Command command) {
        Gson gson = new Gson();
        InfraRedCommand c = gson.fromJson(str, InfraRedCommand.class);
        log.info(c.toString());
        RoomBoxInfo boxInfo = c.getBoxInfo();
        c.assCommand(command);
        command.setDataList(Stream.of(
                Integer.toHexString(c.getType()),
                Integer.toHexString(c.getAddr()),
                Integer.toHexString(c.getKey1()),
                Integer.toHexString(c.getKey2()),
                Integer.toHexString(c.getKey3()),
                Integer.toHexString(c.getKey4()),
                Integer.toHexString(c.getKey5())
        ).collect(Collectors.toList()));
        return boxInfo.getBoxId();
    }

}
